package com.kpx.app.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.LinearLayout;

import com.kpx.app.R;
import com.kpx.app.base.ActivityBase;
import com.kpx.app.bean.OrderBean;
import com.kpx.app.bean.OrderStatusMenuBean;
import com.kpx.app.configs.BroadcastFilters;
import com.kpx.app.utils.UIUtils;
import com.kpx.app.view.TitleView;
import com.kpx.app.view.ViewOrderShow;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * created by :cc
 * 根据订单状态的订单列表
 */
public class ActivityOrderListByStatus extends ActivityBase {


    public static int orderType;
    @BindView(R.id.titleview)
    TitleView title_view;
    @BindView(R.id.ll_container)
    LinearLayout ll_container;
    /**
     * 订单状态选择结果码
     */
    private static int RESULT_CODE_FOR_ORDER_STATUS = 101;
    private OrderStatusMenuBean statusMenuBean;
    private ViewOrderShow showView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public void initview(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_order_list_by_status);
        ButterKnife.bind(this);
        if(orderType== OrderBean.ORDER_STATUS_MY_GOODS){
            UIUtils.setNormalTitle(title_view,"我的实物");
        }else {
            UIUtils.setNormalTitle(title_view,"订单列表");
        }
        getIntentData();
        ll_container = (LinearLayout) findViewById(R.id.ll_container);
        statusMenuBean = new OrderStatusMenuBean();
        statusMenuBean.setStatus(orderType);
        showView = new ViewOrderShow(ActivityOrderListByStatus.this, statusMenuBean);
        ll_container.addView(showView);
//        //点击进入订单筛选
//        title_view.setTitle(statusMenuBean.getTitle(), new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Bundle bundle = new Bundle();
//                bundle.putSerializable(getResources().getString(R.string.intent_key_bean), statusMenuBean);
//                ActivityOrderStatusSelect.inType = 1;
//                IntentUtil.gotoActivityForResult(ActivityOrderListByStatus.this, ActivityOrderStatusSelect.class, bundle, RESULT_CODE_FOR_ORDER_STATUS);
//            }
//        });
//        Drawable drawable = getResources().getDrawable(R.drawable.super_market_order_right_icon);
//        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());// 这一步必须要做,否则不会显示.
//        title_view.getTitle().setCompoundDrawables(null, null, drawable, null);
//        title_view.getTitle().setCompoundDrawablePadding(DisplayUtil.dip2px(ActivityOrderListByStatus.this, 5));
        initEvent();
    }

    @Override
    public void initData() {

    }

    @Override
    public void onReceiver(Context context, Intent intent) {
        if (intent.getAction().equals(BroadcastFilters.BROADCAST_ACTION_SUPERMARKET_REFRESH_ONE_ORDER)) {//超市订单详情操作之后发送广播刷新指定订单状态
            if (statusMenuBean.getStatus() == -1) {
                showView.reflushOrder(intent);
            }
        }else
        if(intent.getAction().equals(BroadcastFilters.BROADCAST_ACTION_REFRESH_DATA)){
            showView.goReflush();
        }
    }

    private void getIntentData() {
    }

    @Override
    protected void onResume() {
        super.onResume();
        showView.goReflush();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK && requestCode == RESULT_CODE_FOR_ORDER_STATUS) {
            OrderStatusMenuBean intentbean = (OrderStatusMenuBean) data.getSerializableExtra(getResources().getString(R.string.intent_key_position));
            if (intentbean != null) {
                statusMenuBean = intentbean;
                title_view.setTitle(statusMenuBean.getTitle());
                showView.setData(statusMenuBean);
            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
    private void initEvent() {
    }
}
